feat(postgresql): add accurate analyzer mode for database-only analysis#4209
Draft
kyleconroy wants to merge 5 commits intomainfrom
Draft
feat(postgresql): add accurate analyzer mode for database-only analysis#4209kyleconroy wants to merge 5 commits intomainfrom
kyleconroy wants to merge 5 commits intomainfrom
Conversation
Add an optional `analyzer.accurate: true` mode for PostgreSQL that bypasses
the internal catalog and uses only database-backed analysis.
Key features:
- Uses database PREPARE for all type resolution (columns, parameters)
- Uses expander package for SELECT * and RETURNING * expansion
- Queries pg_catalog to build catalog structures for code generation
- Skips internal catalog building from schema files
Configuration:
```yaml
sql:
- engine: postgresql
database:
uri: "postgres://..." # or managed: true
analyzer:
accurate: true
```
This mode requires a database connection and the schema must exist in the
database. It provides more accurate type information for complex queries.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add three end-to-end test cases for the accurate analyzer mode: 1. accurate_star_expansion - Tests SELECT *, INSERT RETURNING *, UPDATE RETURNING *, DELETE RETURNING * 2. accurate_enum - Tests enum type introspection from pg_catalog 3. accurate_cte - Tests CTE (Common Table Expression) with star expansion All tests use the managed-db context which requires Docker to run PostgreSQL containers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Update expected output files to match actual sqlc generate output: - Fix parameter naming (Column1, Column2, dollar_1) - Fix nullability types (sql.NullString, sql.NullInt32) - Fix CTE formatting (single line) - Fix query semicolons 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Tests CTE using VALUES clause with column aliasing to verify accurate analyzer handles inline table expressions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The VALUES clause was incorrectly formatting multiple rows as a single
row with multiple columns. For example:
VALUES ('A'), ('B'), ('C')
was being formatted as:
VALUES ('A', 'B', 'C')
This caused the star expander to think the VALUES table had 3 columns
instead of 1, resulting in incorrect SELECT * expansion.
The fix properly iterates over each row in ValuesLists and wraps each
in parentheses.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
analyzer.accurate: truemode for PostgreSQL that bypasses the internal catalog and uses only database-backed analysis for more accurate type information.Key Features
PREPAREstatements for all column and parameter type inferenceSELECT *andRETURNING *expansionpg_catalogto build catalog structures needed for code generation (tables, columns, enums)Configuration
Requirements
database.uriordatabase.managed: true)Files Changed
internal/config/config.goAccurate *boolto Analyzer structinternal/config/v_one.json,v_two.jsonaccurateboolean to analyzer schemainternal/engine/postgresql/analyzer/analyze.goIntrospectSchema(),EnsurePool(),GetColumnNames()methodsinternal/compiler/engine.gointernal/compiler/compile.gointernal/compiler/parse.goTest plan
🤖 Generated with Claude Code